package Sorting;

import java.util.Arrays;
import java.util.Random;

public class Test {
    public static void initArray(int[] array){
        for (int i = 0; i < array.length; i++) {
            array[i] = i;
            //array[i] = array.length-i;//逆序, 直接插入排序耗时：3272
        }
    }
    public static void initNotArray(int[] array){
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(10_0000);
        }
    }
    public static void testInsetSort(int[] array){
        Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.insertSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("直接插入排序耗时："+(endTime-startTime));

    }
    public static void testShellSort(int[] array){
        Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.shellSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("希尔插入排序耗时："+(endTime-startTime));

    }

    public static void testSelectSort(int[] array){
        Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.selectSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("选择排序耗时："+(endTime-startTime));

    }
    public static void testQuickSort(int[] array){
        Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.quickSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("快速排序耗时："+(endTime-startTime));

    }
    public static void testQuickSort2(int[] array){
        Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.quickSort2(array);
        long endTime = System.currentTimeMillis();
        System.out.println("快速排序耗时："+(endTime-startTime));

    }


    public static void initNotArray2(int[] array){
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(100);
        }
    }

    public static void testSelectSort2(int[] array){
        Arrays.copyOf(array,array.length);
        System.out.println(Sort.selectSort(array));

    }


    public static void main(String[] args) {
        int[] array = new int[100];
        initNotArray2(array);
        testSelectSort2(array);
    }


    public static void main13(String[] args) {
        int[] arr = {99,65,49,25,37,9,5,102,152,9996,25,0,45};
        Sort.mergeSort2(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static void main12(String[] args) {
        int[] arr = {99,65,49,25,37,9,5,102,152,9996,25,0,45};
        Sort.quickSort2(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static void main11(String[] args) {
        int[] array = new int[10_0000];
        initArray(array); //有序：直接插入排序耗时：5
        // 逆序：也是最快情况：直接插入排序耗时：3272
        //initNotArray(array); //无序：直接插入排序耗时：1415


        //testInsetSort(array);
        //testShellSort(array);
        //testSelectSort(array);
        testQuickSort(array);

    }

    public static void main10(String[] args) {
        int[] arr = {99,65,49,25,37,9,5,102,152,9996,25,0,45};
        Sort.quickSort(arr);
        System.out.println(Arrays.toString(arr));
    }
    public static void main9(String[] args) {
        int[] arr = {99,65,49,25,37};
        Sort.bubbleSort(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static void main8(String[] args) {
        int[] arr = {99,65,49,25,37};
        Sort.heapSort(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static void main7(String[] args) {
        int[] arr = {99,65,49,25,37};
        Sort.selectSort2(arr);
        System.out.println(Arrays.toString(arr));
    }



    public static void main5(String[] args) {
        int[] arr = {27,15,9,18,28};
        Sort.selectSort(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static void main3(String[] args) {
        int[] arr = {9,1,2,5,7,4,8,6,3,5};
        Sort.shellSort(arr);
        System.out.println(Arrays.toString(arr));
    }


    public static void main1(String[] args) {
        int[] arr = {27,15,19,18,28,34,65,49,25,37};
        Sort.insertSort(arr);
        System.out.println(Arrays.toString(arr));
    }
}
